import { apiInit } from '@/services/index'
const api = apiInit().default
import { showFailToast } from 'vant'
export const getapplicationList = ({
	page_index,
	page_size,
	create_time_end,
	create_time_start = '',
	status = '',
	subject = '',
	time_sort = '',
	type_key_list = '',
}: any) => {
	return api
		.ListApplicationTaskPrivateV2POST({
			payload: {
				page: {
					page_index,
					page_size,
				},
				query: {
					create_time_end,
					create_time_start,
					status,
					subject,
					time_sort,
					type_key_list,
				},
			},
		})
		.then(({ state, data }) => {
			if (state === 'SUCCESS') {
				return data
			}
		})
		.catch(err => {
			console.log(err)
		})
}

export const getListDraft = ({
	page_index,
	page_size,
	keywords,
	name = '',
	time_sort = '',
}: any) => {
	return api
		.ListDraftPrivateV2POST({
			payload: {
				page: {
					page_index,
					page_size,
				},

				query: {
					keywords,
					name,
					time_sort,
				},
			},
		})
		.then(({ state, data }) => {
			if (state === 'SUCCESS') {
				return data
			}
		})
		.catch(err => {
			console.log(err)
		})
}

export const getCount = () => {
	return api
		.CountByTypeApplicationTaskPrivateV2POST({})
		.then(({ state, data }) => {
			if (state === 'SUCCESS') {
				return data
			}
		})
		.catch(err => {
			console.log(err)
		})
}

export const getDraftCount = () => {
	return api
		.CountTaskPrivateV2POST({})
		.then(({ state, data }) => {
			if (state === 'SUCCESS') {
				return data
			}
		})
		.catch(err => {
			console.log(err)
		})
}
export const getAllCount = ({
	create_time_end = '',
	create_time_start = '',
	status = 'approve',
	subject = '',
	time_sort = 'desc',
	type_key_list = '',
}) => {
	return api
		.CountApplicationTaskPrivateV2POST({
			payload: {
				create_time_end,
				create_time_start,
				status,
				subject,
				time_sort,
				type_key_list,
			},
		})
		.then(({ state, data }) => {
			if (state === 'SUCCESS') {
				return data
			}
		})
		.catch(err => {
			console.log(err)
		})
}
export const deleteDrafts = ({ draft_list = [] }) => {
	return api
		.DeleteDraftPrivateV2POST({
			payload: {
				draft_list,
			},
		})
		.then(({ state, data, message }) => {
			if (state === 'SUCCESS') {
				return data
			} else {
				showFailToast(message as any)
			}
		})
		.catch(err => {
			console.log(err)
		})
}
